package com.loe.ktui

import android.content.Context
import android.view.View

/**
 * ktUI主类
 *
 * @author 章路顺
 * @since 2022/9/30-16:21
 */
object KtUi
{
    private var idCount = 100

    /** id映射 */
    private val idMap = HashMap<String, Int>()

    fun addId(id: String, view: View)
    {
        val intId = idMap[id]
        if (intId != null)
        {
            view.id = intId
        } else
        {
            idMap[id] = ++idCount
            view.id = idCount
        }
    }

    fun getId(id: String): Int = idMap[id] ?: 0

    fun clearId() = idMap.clear()

    /** 链接监听 */
    var onLink: ((context: Context, link: String) -> Unit)? = null
        private set

    /** 设置链接监听 */
    fun setOnLink(onLink: (context: Context, link: String) -> Unit)
    {
        this.onLink = onLink
    }
}